/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package userObservers;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.OpenNI.*;

/**
 *
 * @author xvanek9
 */
public class NewUserObserver implements IObserver<UserEventArgs> {

    PoseDetectionCapability posDetCap;
    SkeletonCapability skelDetCap;

    public NewUserObserver(PoseDetectionCapability posDetCap, SkeletonCapability skelCap) {
        this.posDetCap = posDetCap;
        this.skelDetCap = skelCap;
    }
    
    @Override
    public void update(IObservable<UserEventArgs> io, UserEventArgs args) {
        System.out.println("New user being tracked.");
        System.out.println("User's id is " + args.getId());
        try {
            
            posDetCap.startPoseDetection(skelDetCap.getSkeletonCalibrationPose(), args.getId());
            if (skelDetCap.needPoseForCalibration()){
                posDetCap.startPoseDetection(skelDetCap.getSkeletonCalibrationPose(),args.getId());
//                System.out.println("Pose detection started.");
            }else{
                skelDetCap.requestSkeletonCalibration(args.getId(), true);
//                System.out.println("Try to stand in standard position. Kinect is not able to track your bones.");
            }
        } catch (StatusException ex) {
            Logger.getLogger(NewUserObserver.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
}
